import { Injectable } from '@nestjs/common';

@Injectable()
export class ResponseUtilService {

    static successRes(data:any = null, params?:{[key : string] : any}, msg?:string) {
        let result:{[key : string] : any} = {
            success : true,
            data : null,
            msg : msg,
            code : 0
        }
    
        if(data !== null) {
            result.data = data
        }
    
        if(params) {
            result = Object.assign(result, params)
        }
    
        return result
        
    }
    
    static failRes(msg?:string, params?:{[key : string] : any}) {
        let result:{[key : string] : any} = {
            success : false,
            data : null,
            msg : msg,
            code : 0
        }
    
        if(msg !== undefined) {
            result.msg = msg
        }
    
        if(params) {
            result = Object.assign(result, params)
        }
    
        return result
        
    }
    
}
